home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- // Copyright (C) 1997-1998 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- //
- // Alias|Wavefront Script File
- // MODIFY THIS AT YOUR OWN RISK
- //
- // Creation Date: 3 Aug 1998
- // Author: Vangelis Kokkevis
- //
- // Procedure Name:
- // createSkinCluster
- //
- // Description:
- // Creates a skinCluster out of each of the selected
- // pieces of geometry
- //
- // Example:
- // Select all the geometries to be included in the skin
- // and one joint and run "createSkinCluster".
- //
- // If multiple joints are selected then the skinCluster
- // will be bound only to the individual joints
- //
-
- proc string connectedToSkinCluster(string $node)
- //
- // Description:
- // Returns the name of the skinCluster in the history of
- // a particular node. If there's no skinCluster in the
- // history then it returns the empty string
- //
- {
- string $histL[] = `listHistory $node`;
- string $hist;
- for($hist in $histL)
- if (nodeType($hist) == "skinCluster")
- return $hist;
-
- return "";
- }
-
-
- global proc string[] createSkinCluster(string $args)
- {
- string $result[];
- int $clusterCount;
-
- // Get the currenly selected objects
- //
- string $sel[] = `ls -sl`;
- if (!size($sel)) {
- error("Select objects to bind.");
- return $result;
- }
-
- // Find the joints in the selection list
- //
- int $i;
- string $joints;
- int $jointCount;
- for($i=0;$i<size($sel);$i++)
- {
- $item = $sel[$i];
- if (nodeType($item) == "joint")
- {
- $joints = $joints + " " + $item;
- $jointCount++;
- }
- }
-
- if ($jointCount == 0)
- {
- error("You must select at least one joint.");
- return $result;
- }
-
- // Create the skin clusters
- //
- string $cmd;
- int $shapeCount = 0;
- int $j;
- string $validShapes[];
- string $componentShapes[];
- int $compShapeCount = 0;
- string $buf[];
- for($i=0;$i<size($sel);$i++)
- {
- $item = $sel[$i];
- if (nodeType($item) != "joint")
- {
- // Check if we are dealing with a whole shape
- // or just individual components
- //
- if (tokenize($item,".",$buf) == 1)
- {
- string $allShapesCmd = "ls -lf -dag "+"\""+$item+"\"";
- string $allShapes[] = eval($allShapesCmd);
- for ($j=0;$j<size($allShapes);$j++)
- {
- string $nt[] = `ls -type controlPoint $allShapes[$j]`;
- int $io = `getAttr ($allShapes[$j]+".io")`;
- if (size($nt) && ! $io) {
- int $found = 0;
- for($vShape in $validShapes) {
- if ($vShape == $allShapes[$j]) {
- $found = true;
- break;
- }
- }
- if (!$found) {
- $validShapes[$shapeCount++] = $allShapes[$j];
- }
- }
- }
- }
- else
- {
- string $nt[] = `ls -lf -dag -type controlPoint $buf[0]`;
- int $io = `getAttr ($buf[0]+".io")`;
- if (size($nt) && !$io)
- {
- // Check if other components of that shape
- // are in the same list
- //
- int $found = false;
- string $cShape;
- for($cShape in $componentShapes)
- if ($cShape == $buf[0])
- {
- $found = true;
- break;
- }
- if (!$found)
- {
- $componentShapes[$compShapeCount++] = $buf[0];
- }
- }
- }
- }
- }
-
- // Deal with surfaces bound as a whole
- //
- string $cmd;
- for ($j = 0; $j < $shapeCount; $j++) {
- $cmd = "skinCluster "+ $args + " ";
- $cmd = $cmd + $joints + " " + $validShapes[$j];
- string $res[];
-
- if ($j == ($shapeCount-1) && 0 == $clusterCount) {
- // on the very last shape, if we have not yet created any
- // clusters, we eval without a catch so that the script will
- // quit on the error rather than printing out an empty result
- //
- $res = eval($cmd);
- $result[$clusterCount++] = $res[0];
- } else {
- if (!catch($res = eval($cmd))) {
- $result[$clusterCount++] = $res[0];
- }
- }
- }
-
- // Deal with surfaces whose components are bound
- //
- string $cShape;
- int $count = 0;
- for ($cShape in $componentShapes)
- {
- // If the surface already has a skin cluster attached
- // then just add the selected points to the existing
- // skin cluster set
- //
- string $skinCluster = connectedToSkinCluster($cShape);
- int $foundSet = false;
- if ($skinCluster != "")
- {
- if ("toSelectedBones" == match("toSelectedBones",$args)) {
- // Are the selected bones influence objects yet? If not
- // we need to add them as influence objects. We'll also lock
- // all weights while we do this so we do not affect anything
- // else in the scene.
- //
-
- // First, find the missing influences
- //
- string $currentInfluences[] = `skinCluster -q -inf $skinCluster`;
- string $selectedJoints[] = `ls -sl -type transform`;
- string $missingInfluences[];
- int $sizeMI = 0;
- for ($sJoint in $selectedJoints) {
- int $found = 0;
- for ($cInfluence in $currentInfluences) {
- if ($sJoint == $cInfluence) {
- $found = 1;
- break;
- }
- }
- if (! $found) {
- $missingInfluences[$sizeMI] = $sJoint;
- $sizeMI += 1;
- }
- }
-
- // Now, add the missing influences
- //
- if ($sizeMI > 0) {
- // lock all other influences
- //
- string $currentlyLockedInfluences[];
- int $sizeCLI = 0;
- for ($cInfluence in $currentInfluences) {
- if (getAttr ($cInfluence+".liw")) {
- $currentlyLockedInfluences[$sizeCLI] = $cInfluence;
- $sizeCLI += 1;
- }
- setAttr ($cInfluence+".liw") 1;
- }
-
- // actually add the missing influences
- //
- for ($mInfluence in $missingInfluences) {
- skinCluster -e -ai $mInfluence $skinCluster;
- }
-
- // unlock the other influences, unless they were previously
- // locked
- //
- for ($cInfluence in $currentInfluences) {
- int $found = 0;
- for ($lInfluence in $currentlyLockedInfluences) {
- if ($lInfluence == $cInfluence) {
- $found = 1;
- break;
- }
- }
- if (! $found) {
- setAttr ($cInfluence+".liw") 0;
- }
- }
- }
- }
-
- string $connL[] = `listConnections -type objectSet ($skinCluster+".message")`;
- string $conn;
- for ($conn in $connL)
- {
- if (nodeType($conn) == "objectSet")
- {
- $foundSet = true;
- $cmd = "sets -fe " + $conn + " ";
- }
- }
- }
-
- // If a skinCluster is not found then just use
- // the skinCluster command to create a new one
- //
- if (!$foundSet)
- $cmd = "skinCluster "+ $args + " " + $joints + " ";
-
- for($s in $sel)
- {
- if (tokenize($s, ".", $buf) != 1 &&
- $buf[0] == $cShape)
- {
-
- $cmd = $cmd + $s + " ";
- }
- }
-
- string $res[];
- if ($count == ($compShapeCount-1) && 0 == $clusterCount)
- {
- if ($foundSet)
- {
- eval($cmd);
- $result[$clusterCount++] = $skinCluster;
- }
- else
- {
- $res = eval($cmd);
- $result[$clusterCount++] = $res[0];
- }
- }
- else
- {
- if ($foundSet)
- {
- if (!catch(eval($cmd)))
- $result[$clusterCount++] = $skinCluster;
- }
- else
- {
- if (!catch($res = eval($cmd)))
- $result[$clusterCount++] = $res[0];
- }
- }
-
- $count++;
- }
-
-
- if ($shapeCount == 0 && $compShapeCount == 0) {
- error("Bind-able objects must be selected.");
- }
-
- return $result;
- }
-
-
-
-
-
-